package com.xidian.zhiancloud.service.luling.PointPart;
import com.xidian.zhiancloud.controller.luling.PointPart.CraftNodeStatusListQO;
import com.xidian.zhiancloud.dao.CraftNodeStatusMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.CraftNodeStatus;
import com.xidian.zhiancloud.model.CraftNodeStatusExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CraftNodeStatusService {
    @Autowired
    private CraftNodeStatusMapper craftNodeStatusMapper;
    //添加
    public void insert(CraftNodeStatus craftNodeStatus) {
        int count = craftNodeStatusMapper.insert(craftNodeStatus);
        if (count == 0) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }
    //删除
    public void delete(CraftNodeStatus craftNodeStatus) {
        CraftNodeStatusExample example = new CraftNodeStatusExample();
        CraftNodeStatusExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(craftNodeStatus.getId());
        int count = craftNodeStatusMapper.deleteByExample(example);
        if (count == 0) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }
    //修改
    public void update(CraftNodeStatus craftNodeStatus) {
        CraftNodeStatusExample example = new CraftNodeStatusExample();
        CraftNodeStatusExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(craftNodeStatus.getId());
        CraftNodeStatus node = new CraftNodeStatus();
        node.setNodeType(craftNodeStatus.getNodeType());
        int count = craftNodeStatusMapper.updateByExampleSelective(node, example);
        if (count == 0) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }
    //批量删除
    public void deleteByIds(Long[] ids) {
        for (Long id : ids) {
            int result = craftNodeStatusMapper.deleteByPrimaryKey(id);
            if (result == 0) {
                throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
            }
        }
    }
    //通过工艺节点类型查询
    public List<CraftNodeStatus> getById(String nodeType) {
        CraftNodeStatusExample craftNodeStatusExample = new CraftNodeStatusExample();
        CraftNodeStatusExample.Criteria criteria = craftNodeStatusExample.createCriteria();
        criteria.andNodeTypeEqualTo(nodeType);
        List<CraftNodeStatus> craftNodeStatusList = craftNodeStatusMapper.selectByExample(craftNodeStatusExample);
        if (craftNodeStatusList == null) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
        return craftNodeStatusList;
    }
    //关键字搜索
    public List<CraftNodeStatus> getList(String nodeName, String introduction, String addBy,String key, int current, int size){
        CraftNodeStatusExample  craftNodeStatusExample = new CraftNodeStatusExample();
        if (nodeName != null) {
            craftNodeStatusExample.getOredCriteria().get(0).andnodeNameEqualTo(nodeName);
        }
        if (introduction != null) {
            craftNodeStatusExample.getOredCriteria().get(0).andintroductionEqualTo(introduction);
        }
        if (addBy != null) {
            craftNodeStatusExample.getOredCriteria().get(0).andaddByEqualTo(addBy);
        }
        if (key != null) {
            craftNodeStatusExample.getOredCriteria().get(0).andkeyEqualTo(key);
        }
        return craftNodeStatusMapper.selectByExampleWithRowbounds(craftNodeStatusExample, new RowBounds(current, size));
    }

    public Object getListByQO(CraftNodeStatusListQO craftNodeStatusListQO) {
        return null;
    }


}
//导入导出
